package net.caixiaomi.info.Lottery.adapter;

import net.caixiaomi.info.Lottery.model.LotteryCathecticCellEntity;
import net.caixiaomi.info.Lottery.model.LotteryOrderCathecticEntity;
import net.caixiaomi.info.Lottery.view.BallOrderEntity;
import net.caixiaomi.info.Lottery.view.BallOrderView;
import net.caixiaomi.info.R;
import net.caixiaomi.info.base.quickadapter.BaseMultiItemQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.base.quickadapter.entity.MultiItemEntity;
import net.caixiaomi.info.util.Constants;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by suntian on 2018/8/20.
 */

public class LotteryOrderAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public LotteryOrderAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(Constants.ITEM_VIEW_ITEM, R.layout.lottery_order_item_layout);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        bindItem(helper,item);
    }

    private void bindItem(BaseViewHolder helper, MultiItemEntity item){
        LotteryOrderCathecticEntity entity= (LotteryOrderCathecticEntity) item;
        BallOrderView ballView=helper.getView(R.id.lottery_order_item_ball);
        List<BallOrderEntity> list=new ArrayList<>();
        String content="";
        switch (entity.getPlayType()){
            case 0:
                content="单式";
                for(int i=0;i<entity.getRedCathectics().size();i++){
                    BallOrderEntity ballViewItem=new BallOrderEntity();
                    LotteryCathecticCellEntity eee=entity.getRedCathectics().get(i);
                    ballViewItem.setNum(eee.getCathectic());
                    if(eee.getIsGuess().equals("0")){
                        ballViewItem.setColorType(1);
                    }else{
                        ballViewItem.setColorType(0);
                    }
                    if(i==entity.getRedCathectics().size()-1){
                        ballViewItem.setDivider(1);
                    }else{
                        ballViewItem.setDivider(0);
                    }
                    list.add(ballViewItem);
                }

                for(int i=0;i<entity.getBlueCathectics().size();i++){
                    BallOrderEntity ballViewItem=new BallOrderEntity();
                    LotteryCathecticCellEntity eee=entity.getBlueCathectics().get(i);
                    ballViewItem.setNum(eee.getCathectic());
                    if(eee.getIsGuess().equals("0")){
                        ballViewItem.setColorType(3);
                    }else{
                        ballViewItem.setColorType(2);
                    }
                    list.add(ballViewItem);
                }
                break;
            case 1:
                content="复式";
                for(int i=0;i<entity.getRedCathectics().size();i++){
                    BallOrderEntity ballViewItem=new BallOrderEntity();
                    LotteryCathecticCellEntity eee=entity.getRedCathectics().get(i);
                    ballViewItem.setNum(eee.getCathectic());
                    if(eee.getIsGuess().equals("0")){
                        ballViewItem.setColorType(1);
                    }else{
                        ballViewItem.setColorType(0);
                    }
                    if(i==entity.getRedCathectics().size()-1){
                        ballViewItem.setDivider(1);
                    }else{
                        ballViewItem.setDivider(0);
                    }
                    list.add(ballViewItem);
                }

                for(int i=0;i<entity.getBlueCathectics().size();i++){
                    BallOrderEntity ballViewItem=new BallOrderEntity();
                    LotteryCathecticCellEntity eee=entity.getBlueCathectics().get(i);
                    ballViewItem.setNum(eee.getCathectic());
                    if(eee.getIsGuess().equals("0")){
                        ballViewItem.setColorType(3);
                    }else{
                        ballViewItem.setColorType(2);
                    }
                    list.add(ballViewItem);
                }
                break;
            case 2:
                content="胆拖";
                for(int i=0;i<entity.getRedDanCathectics().size();i++){
                    BallOrderEntity ballViewItem=new BallOrderEntity();
                    LotteryCathecticCellEntity eee=entity.getRedDanCathectics().get(i);
                    ballViewItem.setNum(eee.getCathectic());
                    if(eee.getIsGuess().equals("0")){
                        ballViewItem.setColorType(1);
                    }else{
                        ballViewItem.setColorType(0);
                    }
                    if(i==entity.getRedCathectics().size()-1){
                        ballViewItem.setDivider(1);
                    }else{
                        ballViewItem.setDivider(0);
                    }
                    list.add(ballViewItem);
                }

                BallOrderEntity ivBall0=new BallOrderEntity();
                ivBall0.setNum("——");
                ivBall0.setColorType(5);
                list.add(ivBall0);

                for(int i=0;i<entity.getRedTuoCathectics().size();i++){
                    BallOrderEntity ballViewItem=new BallOrderEntity();
                    LotteryCathecticCellEntity eee=entity.getRedTuoCathectics().get(i);
                    ballViewItem.setNum(eee.getCathectic());
                    if(eee.getIsGuess().equals("0")){
                        ballViewItem.setColorType(1);
                    }else{
                        ballViewItem.setColorType(0);
                    }
                    if(i==entity.getRedCathectics().size()-1){
                        ballViewItem.setDivider(1);
                    }else{
                        ballViewItem.setDivider(0);
                    }
                    list.add(ballViewItem);
                }

                BallOrderEntity ivBall1=new BallOrderEntity();
                ivBall1.setNum("——");
                ivBall1.setColorType(5);
                list.add(ivBall1);

                for(int i=0;i<entity.getBlueDanCathectics().size();i++){
                    BallOrderEntity ballViewItem=new BallOrderEntity();
                    LotteryCathecticCellEntity eee=entity.getBlueDanCathectics().get(i);
                    ballViewItem.setNum(eee.getCathectic());
                    if(eee.getIsGuess().equals("0")){
                        ballViewItem.setColorType(3);
                    }else{
                        ballViewItem.setColorType(2);
                    }
                    if(i==entity.getRedCathectics().size()-1){
                        ballViewItem.setDivider(1);
                    }else{
                        ballViewItem.setDivider(0);
                    }
                    list.add(ballViewItem);
                }

                BallOrderEntity ivBall2=new BallOrderEntity();
                ivBall2.setNum("——");
                ivBall2.setColorType(5);
                list.add(ivBall2);

                for(int i=0;i<entity.getBlueTuoCathectics().size();i++){
                    BallOrderEntity ballViewItem=new BallOrderEntity();
                    LotteryCathecticCellEntity eee=entity.getBlueTuoCathectics().get(i);
                    ballViewItem.setNum(eee.getCathectic());
                    if(eee.getIsGuess().equals("0")){
                        ballViewItem.setColorType(3);
                    }else{
                        ballViewItem.setColorType(2);
                    }
                    if(i==entity.getRedCathectics().size()-1){
                        ballViewItem.setDivider(1);
                    }else{
                        ballViewItem.setDivider(0);
                    }
                    list.add(ballViewItem);
                }

                break;
        }
        ballView.clearBalls();
        ballView.setEntity(list,10);
        content=content+"  "+entity.getBetNum()+"注  "+entity.getCathectic()+"倍  "+entity.getAmount()+"元";
        if(entity.getIsAppend()==1){
            content=content+"  "+"已追加";
        }
        helper.setText(R.id.lottery_order_item_ball_tv,content);
    }

}
